Esoteric Ant Hacks

When debugging ant build scripts (fun wow,) sometimes you want to view the contents of a path reference, this handy hack does just the trick:

<echo message="${toString:pathref}"/>

It probably also works for other “classes” as well.

After a little more digging around (my ant is a little rusty) the proper way to do this is to convert your path reference to a property:

<property name="class.path" refid="class.path.ref"/>

Finally a little sugar to print out your classpath in a human readble form:

<!-- pretty print the class path so it is human readable -->
<macrodef name=\"print_classpath\">
 <attribute name=\"path\"></attribute>
 <attribute name=\"description\" default=\"=== CLASSPATH ===\"></attribute>
 <sequential>
    <echo>@{description}</echo>
    <for list=\"@{path}\" param=\"pathitem\" delimiter=\";\">
       <sequential>
          <echo>pathitem == @{pathitem}${line.separator}</echo>
       </sequential>
    </for>
    </sequential>
</macrodef>

Note you will need the for loop from ant contrib to use this macro/task

<<taskdef resource=\"net/sf/antcontrib/antlib.xml\" classpathref=\"ant.classpath.tools.lib\">

Leave a Reply